package main

import (
	"fmt"
)

func main() {
	c := Chinese{}
	greet(c)

	a := American{}
	greet(a)
}


// 接口
type SayHello interface {
	sayHello()
}

// 接口实现
type Chinese struct {
	name string
}
func (person Chinese) sayHello() {
	fmt.Println("你好")
}
func (person Chinese) chineseGF() {
	fmt.Println("中国功夫")
}

type American struct {
	name string
}
func (person American) sayHello() {
	fmt.Println("hi")
}

// 定义函数,接受具备sayhello接口的变量
func greet(s SayHello) {
	s.sayHello()

	// s.chineseGF()
	// 断言
	ch, flag := s.(Chinese)
	if flag == true {
		ch.chineseGF()
	}

	if ch, flag := s.(Chinese); flag {
		ch.chineseGF()
	}

	switch s.(type) {
		case Chinese:
			ch := s.(Chinese)
			ch.chineseGF()
		case American:
			en := s.(American)
			// ..
			
	}
}